﻿Public Class frmBranchReserveRoom
    Private da As New DSVaultingTableAdapters.rr_reserve_room_branchesTableAdapter
    Private action As String
    Private actType As String() = {"NONE", "INSERT", "UPDATE", "DELETE"}
    Private oldID As Long

    Private Sub frmBranchReserveRoom_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.updateDGV()
    End Sub

    Private Sub updateDGV()
        uxBranchDgv.DataSource = da.GetData
    End Sub

    Private Sub frmBranchReserveRoom_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        frmSetting.Enabled = True
    End Sub

    Private Sub uxSaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxSaveBtn.Click
        Dim val As String = uxInputRRTbx.Text
        If Not uxInputRRTbx.Text = "" Then
            If action = actType(1) Then
                da.Insert(val)
                uxInputRRTbx.Clear()
                updateDGV()
            ElseIf action = actType(2) Then
                da.Update(val, oldID)
                updateDGV()
            End If
        End If
    End Sub

    Private Sub uxNewBranchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxNewBranchBtn.Click
        uxInputRRTbx.Enabled = True
        action = actType(1)
    End Sub

    Private Sub uxEditBranchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxEditBranchBtn.Click
        If uxBranchDgv.SelectedRows.Count > 0 Then
            uxInputRRTbx.Enabled = True
            uxInputRRTbx.Text = uxBranchDgv.SelectedRows.Item(0).Cells("location").Value
            If Not uxInputRRTbx.Text = "" Then
                oldID = uxBranchDgv.SelectedRows.Item(0).Cells(0).Value
                action = actType(2)
            End If
        End If
    End Sub

    Private Sub uxCancelBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxCancelBtn.Click
        frmSetting.Enabled = True
        Me.Close()
    End Sub

    Private Sub uxInputRRTbx_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles uxInputRRTbx.KeyPress
        If e.KeyChar = ChrW(Keys.Enter) Then
            uxSaveBtn_Click(sender, e)
        End If
    End Sub

    Private Sub uxBranchDgv_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles uxBranchDgv.CellDoubleClick
        uxEditBranchBtn_Click(sender, e)
    End Sub
End Class